var t = getApp();

Page({
    data: {
        isLoadMore: !0,
        page: 1,
        total_page: 0
    },
    onLoad: function(t) {
        var a = wx.getStorageSync("langIndex");
        this.setData({
            language: a.en
        }), this.options.topic_id && (this.setData({
            topic_id: t.topic_id
        }), this.getinfo(), this.getData());
    },
    toGoods: function(t) {
        var a = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageA/detail_v2/detail_v2?id=" + a
        });
    },
    getinfo: function() {
        var a = this, o = t.getNetAddresss("plugin.project-template.frontend.topic.getTopicByTopicId");
        t._postNetWork({
            url: o,
            data: {
                topic_id: this.data.topic_id
            },
            success: function(t) {
                var o = t.data;
                1 == o.result ? (a.setData({
                    info: o.data
                }), wx.setNavigationBarTitle({
                    title: a.data.info.title
                })) : wx.showToast({
                    title: o.msg,
                    icon: "none",
                    duration: 1e3
                });
            },
            fail: function(t) {}
        });
    },
    getData: function() {
        var a = this, o = t.getNetAddresss("plugin.project-template.frontend.topic.getTopicGoodsByTopicId");
        t._postNetWork({
            url: o,
            data: {
                page: this.data.page,
                topic_id: this.data.topic_id
            },
            success: function(t) {
                var o = t.data;
                if (1 == o.result) {
                    var e = o.data;
                    a.setData({
                        isLoadMore: !0,
                        total_page: e.last_page,
                        list: e.data
                    }), a.data.total_page || (a.data.total_page = 0), a.data.page >= a.data.total_page && a.setData({
                        isLoadMore: !1
                    });
                } else wx.showToast({
                    title: o.msg,
                    icon: "none",
                    duration: 1e3
                });
            },
            fail: function(t) {}
        });
    },
    _getMoreData: function() {
        var a = this;
        if (this.data.page >= this.data.total_page) return this.setData({
            isLoadMore: !1
        }), void wx.hideLoading({
            success: function(t) {}
        });
        this.setData({
            page: this.data.page + 1
        });
        var o = t.getNetAddresss("plugin.find-point-reward.frontend.controllers.center");
        t._postNetWork({
            url: o,
            data: {
                page: this.data.page,
                topic_id: this.data.topic_id
            },
            success: function(t) {
                var o = t.data;
                if (1 == o.result) {
                    var e = o.data, i = a.data.list.concat(o.data);
                    a.setData({
                        isLoadMore: !0,
                        total_page: e.last_page,
                        list: i
                    });
                } else wx.showToast({
                    title: o.msg,
                    icon: "none",
                    duration: 1e3
                });
            },
            fail: function(t) {}
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? this._getMoreData() : console.log("没有更多数据");
    },
    onShareAppMessage: function() {}
});